<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
<title>Create Product</title>
<script type="text/javascript">
	function validateForm() {
		var prodCat = document.getElementById('prodCat').value;
		var prodName = document.getElementById('prodName').value;
		var prodPicture = document.getElementById('prodPicture').value;
		var prodPrice = document.getElementById('prodPrice').value;
		var sellerComment = document.getElementById('sellerComment').value;

		var errorText = "";

		if (prodCat == "") {
			errorText += "- Product Category is mandatory";
			errorText += "\n"
		}

		if (prodName == "") {
			errorText += "- Product Name is mandatory";
			errorText += "\n"
		}

		if (prodPrice == "") {
			errorText += "- Product Price is mandatory";
			errorText += "\n"
		}

		return errorText;

	}

	function submitForm() {
		var errorText = validateForm();
		if (errorText == "") {
			document.getElementById('myform').submit();
		} else {
			alert(errorText);
			return false;
		}
	}
</script>
</head>
<body>
	<c:choose>
		<c:when test="${userSession.type == 'User'}">
			<jsp:include page="/WEB-INF/jsp/page.header.jsp"></jsp:include>
		</c:when>
		<c:otherwise>
		 	<jsp:include page="/WEB-INF/jsp/admin/header.jsp"></jsp:include>
		</c:otherwise>
	</c:choose>	
	<div style="text-align: left">
		<br><br>
		<h1>Create Product</h1>
		<form id="myform" action="/service/product.create.action"
			method="POST" >

			<table border="0" cellpadding="0" cellspacing="0" >
				<tr>
					<td colspan="3">
						
						<br> *) Mandatory Field<br>
						<br>
					</td>
				</tr>
				<tr valign="top">
					<td>Product's Category*</td>
					<td>&#160;:&#160;</td>
					<td><input type="text" value="" name="prodCat" id="prodCat" /></td>
				</tr>
				<tr valign="top">
					<td>Product's Name*</td>
					<td>&#160;:&#160;</td>
					<td><input type="text" value="" name="prodName" id="prodName" /></td>
				</tr>
				<tr valign="top">
					<td>Product's Picture</td>
					<td>&#160;:&#160;</td>
					<td><input type="text" value="" name="prodPicture"
						id="prodPicture" /></td>
				</tr>
				<tr valign="top">
					<td>Product's Price*</td>
					<td>&#160;:&#160;</td>
					<td><input type="text" value="" name="prodPrice"
						id="prodPrice" /></td>
				</tr>
				<tr valign="top">
					<td>Seller's Comment</td>
					<td>&#160;:&#160;</td>
					<td><textarea rows="5" cols="20" name="sellerComment"
						id="sellerComment"></textarea></td>
				</tr>
				<tr><td colspan="3">&#160;</td></tr>
				<tr align="left">
					<td colspan="2">&#160;&#160;</td>
					<td>
						<button id="mybutton" type="button" onclick="submitForm()">Submit</button>
					</td>
				</tr>
			</table>
		</form>

	</div>

</body>
</html>
